home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '93 / Papers '93 / Macintosh as Internet Server ƒ / inetd / Libraries / DaemonApp / UFailure.h < prev   
Encoding:
Text File  |  1993-03-17  |  3.7 KB  |  152 lines  |  [TEXT/MPS ]

  1. // UFailure.h
  2. // Copyright © 1984-1992 by Apple Computer Inc. All rights reserved.
  3.  
  4. #ifndef __UFAILURE__
  5. #define __UFAILURE__
  6.  
  7. #ifdef NEVER
  8. #ifndef __MACAPPTYPES__
  9. #include "MacAppTypes.h"
  10. #endif
  11. #else
  12. #ifndef __PASCALSTRING__
  13. #include "PascalString.h"
  14. #endif
  15. #endif
  16.  
  17. //----------------------------------------------------------------------------------------
  18. // This macro can be called on any variable to keep it out of a register. It is
  19. // used specifically in exception handling. Cludge to be used till volatile or
  20. // C++ exception handling is implemented.
  21. //----------------------------------------------------------------------------------------
  22.  
  23. #define VOLATILE(a) ((void) &a)
  24.  
  25.  
  26. //----------------------------------------------------------------------------------------
  27. // Max and min error number constants
  28. //----------------------------------------------------------------------------------------
  29.  
  30. const short minErr = -32768;
  31. const short maxErr = 32767;
  32.  
  33.  
  34. //----------------------------------------------------------------------------------------
  35. // FailInfo
  36. //----------------------------------------------------------------------------------------
  37.  
  38. class FailInfo
  39. {
  40. public:
  41.     long regs[12];
  42.     short flags;
  43.     short error;
  44.     long message;
  45.     long failA6;
  46.     long failPC;
  47.     FailInfo* nextInfo;
  48. #if qDebug
  49.     long whoPC;
  50.     short installed;
  51. #endif
  52.  
  53. public:
  54.     FailInfo();
  55.  
  56. #if qDebug
  57.     ~FailInfo();
  58. #endif
  59.  
  60.     inline Boolean Try();
  61.  
  62.     inline void ReSignal();
  63.  
  64.     inline void Success();
  65. };
  66.  
  67. typedef struct FailInfo *FailInfoPtr;
  68.  
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // Global variable declarations
  72. //----------------------------------------------------------------------------------------
  73.  
  74. extern FailInfoPtr gTopHandler;
  75.  
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // Global function declarations
  79. //----------------------------------------------------------------------------------------
  80.  
  81. pascal void Assertion(const Boolean condition, const CStr255& description);
  82.  
  83. pascal long BuildMessage(short lowWord, short highWord)
  84. { return (long)highWord << 16 & lowWord; }
  85.  
  86. typedef pascal void(* CatchFailuresType)(short e, long m, void* staticLink);
  87.  
  88. pascal void CatchFailures(FailInfo& fi, CatchFailuresType Handler, void* staticLink);
  89.  
  90. typedef pascal void(* DoToHandlerType)(FailInfoPtr fiPtr, void* staticLink);
  91.  
  92. pascal void EachFailureHandlerDo(DoToHandlerType DoToHandler, void* staticLink);
  93.  
  94. pascal void Failure(OSErr error, long message);
  95.  
  96. pascal void FailMemError();
  97.  
  98. pascal void FailResError();
  99.  
  100. pascal void FailNewMessage(OSErr error, long oldMessage, long newMessage);
  101.  
  102. pascal void FailNIL(void* p);
  103.  
  104. pascal void FailNILResource(Handle r);
  105.  
  106. pascal void FailOSErr(OSErr error);
  107.  
  108. pascal Boolean HandlerExists(FailInfoPtr testFailInfoPtr);
  109.  
  110. pascal void Success(FailInfo& fi);
  111.  
  112. pascal void ProgramBreak(const CStr255& grievance);
  113.  
  114. pascal void ProgramReport(const CStr255& grievance, const Boolean breakInDebugger);
  115.  
  116. extern "C" {
  117. extern Boolean Try(FailInfo& fi);
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // FailInfo inline method definitions
  122. //----------------------------------------------------------------------------------------
  123.  
  124. inline FailInfo::FailInfo()
  125. {
  126. #if qDebug
  127.     installed = FALSE;
  128. #endif
  129. }
  130.  
  131. #if qDebug
  132. inline FailInfo::~FailInfo()
  133. {
  134.     if (installed)
  135.         ProgramBreak("You forgot to call success for your failure handler");
  136. }
  137. #endif
  138.  
  139. inline Boolean FailInfo::Try() { return ::Try(*this); }
  140.  
  141. inline void FailInfo::ReSignal() { ::Failure(error, message); }
  142.  
  143. #if qDebug
  144. inline void FailInfo::Success() { ::Success(*this); }
  145. #else
  146. inline void FailInfo::Success() { gTopHandler = nextInfo; }
  147. #endif
  148.  
  149. #endif
  150.  
  151.  
  152.